//===================================================
//作    者：边涯  http://www.u3dol.com  QQ群：87481002
//创建时间：2015-12-04 22:26:39
//备    注：
//===================================================
using UnityEngine;
using System.Collections; 
using UnityEditor;
using System.Text.RegularExpressions;


namespace Cwl.Fromwork.Editor
{
    /// <summary>
    /// UI层级管理器
    /// </summary>
    public class NPinyinEditor
    {
        [MenuItem("Assets/cwl/ 查找中文及改名")]
        static void CreateTextureConfig()
        {
            Caching.ClearCache();
            Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
            for (int i = 0; i < SelectedAsset.Length; i++)
            {
                //Assets/洒水大所/萨达/安抚.prefab
                string path = AssetDatabase.GetAssetPath(SelectedAsset[i]);
                int index = path.LastIndexOf("/");
                string newPath = path.Substring(0, index);//Assets/洒水大所/萨达
                string name = path.Substring(index + 1, path.Length - index - 1); //安抚.prefab
                name = SelectedAsset[i].name; //安抚
                if (HasChinese(name))
                {
                    string newName = NPinyin.Pinyin.GetPinyin(name).Replace(" ", "");

                    Debug.Log("File " + newPath + "  " + name + "  " + newName);

                    AssetDatabase.RenameAsset(path, newName);
                }
            }
            Debug.Log("查找中文 改名 结束 ");
            AssetDatabase.Refresh();
        }
        // 中文
        static bool HasChinese(string str)
        {
            return Regex.IsMatch(str, @"[\u4e00-\u9fa5]");
        }


    }

}